package com.beantools.execption;

import com.beantools.constants.SingleChar;

import static com.beantools.constants.SingleChar.BLANK_OP;
import static com.beantools.util.ObjectUtil.isNull;

/**
 * 这是<code>HandlerException</code>类，其继承{@link RuntimeException}异常类。
 * 这个类是抛出与处理器相关的异常，比如在这种情况下，如果注解{@link com.beantools.annotation.NotNull}和
 * 注解{@link com.beantools.annotation.NotNull}同时存在，就会抛出这样的异常信息
 * <pre>
 *     <strong>注解<code>NotNull</code>和<code>NotNullIncludeSuper</code>只能使用一个</strong>
 * </pre>
 *
 * @author baoya
 * @version 1.0
 * @since 1.1.0
 */

public class HandlerException extends RuntimeException {

    private Class aClass;

    private String message;

    public HandlerException() {
    }

    public HandlerException(String message) {
        super(message);
        this.message = message;
    }

    public HandlerException(String message, Class aClass) {
        super(message);
        this.message = message;
        this.aClass = aClass;

    }

    @Override
    public String getMessage() {
        if (isNull(aClass)) {
            throw new NullPointerException("当前类字面常量不能为空");
        }
        return "类" + aClass.getName() + "的异常信息" +
                SingleChar.SIGN_COLON_OP + BLANK_OP + this.message;
    }
}


